<template>
<div class="user">
		<!--搜索表单-->
		<div class="common-seach-wrap">
			<el-form size="small" :inline="true" :model="formInline" class="demo-form-inline">
				<el-form-item :label="$t('plus.keyword')">
					<el-input v-model="formInline.search" :placeholder="$t('plus.input_user_info')"></el-input>
				</el-form-item>
				<el-form-item :label="$t('plus.prize_info')">
					<el-input v-model="formInline.recordName" :placeholder="$t('plus.input_prize_name')"></el-input>
				</el-form-item>
				<el-form-item :label="$t('plus.status')">
					<el-select size="small" v-model="formInline.status" :placeholder="$t('plus.please_select')">
						<el-option :label="$t('plus.all')" :value="-1"></el-option>
						<el-option :label="$t('plus.redeemed')" :value="1"></el-option>
						<el-option :label="$t('plus.not_redeemed')" :value="0"></el-option>
					</el-select>
				</el-form-item>
				<el-form-item :label="$t('plus.time')">
					<div class="block">
						<span class="demonstration"></span>
						<el-date-picker v-model="formInline.reg_date" type="daterange" value-format="YYYY-MM-DD"
							:range-separator="$t('plus.to')" :start-placeholder="$t('plus.start_date')" :end-placeholder="$t('plus.end_date')"></el-date-picker>
					</div>
				</el-form-item>
				<el-form-item>
					<el-button type="primary" icon="Search" @click="onSubmit">{{$t('plus.search')}}</el-button>
					<el-button size="small" type="success" @click="onExport">{{$t('plus.export')}}</el-button>
				</el-form-item>
			</el-form>
		</div>
		<!--内容-->
		<div class="product-content">
			<div class="table-wrap">
				<el-table size="small" :data="tableData" border style="width: 100%" v-loading="loading">
					<el-table-column prop="userId" label="ID" width="80"></el-table-column>
					<el-table-column prop="nickName" :label="$t('plus.nickname')"></el-table-column>
					<el-table-column :label="$t('plus.wechat_avatar')">
						<template #default="scope">
							<template v-if="scope.row.avatarUrl">
								<img :src="scope.row.avatarUrl" :width="30" :height="30" />
							</template>
						</template>
					</el-table-column>
					<el-table-column prop="mobile" :label="$t('plus.phone')"></el-table-column>
					<el-table-column prop="recordName" :label="$t('plus.winning_content')"></el-table-column>
					<el-table-column prop="lotteryTypeText" :label="$t('plus.winning_type')"></el-table-column>
					<el-table-column prop="status" :label="$t('plus.status')">
						<template #default="scope">
							<span v-if="scope.row.status == 1">{{$t('plus.redeemed')}}</span>
							<span class="red" v-if="scope.row.status == 0">{{$t('plus.not_redeemed')}}</span>
						</template>
					</el-table-column>
					<el-table-column prop="createTime" :label="$t('plus.lottery_time')" width="140"></el-table-column>
					<el-table-column prop="remark" :label="$t('plus.remark')"></el-table-column>
					<el-table-column fixed="right" :label="$t('plus.action')" width="120">
						<template #default="scope">
							<el-button @click="sendClick(scope.row)" type="text" size="small"
								v-if="scope.row.status === 0 && scope.row.phone">{{$t('plus.issue')}}</el-button>
							<el-button v-if="scope.row.expressId > 0" @click="getLogistics(scope.row)" link
								type="primary" size="small" v-auth="'/order/order/express'">{{$t('plus.view_logistics')}} 
</el-button>
							<el-button @click="remarks(scope.row)" link type="primary" size="small">{{$t('plus.remark')}} 
</el-button>
						</template>
					</el-table-column>
				</el-table>
			</div>
			<!--分页-->
			<div class="pagination">
				<el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" background
					:current-page="curPage" :page-size="pageSize" layout="total, prev, pager, next, jumper"
					:total="totalDataNumber"></el-pagination>
			</div>
		</div>
		<!--处理-->
		<Send v-if="open_send" :open_send="open_send" :model="currentModel" :expressList="expressList"
			@closeDialog="closeDialogFunc($event, 'Send')"></Send>
		<Logistics v-if="isLogistics" :logisticsData="logisticsData" :isLogistics="isLogistics"
			@closeDialog="closeLogistics"></Logistics>
		<remarks v-if="is_remark" :is_remark="is_remark" :Val="remarkVal"
			@closeDialog="closeDialogFunc($event, 'remark')"></remarks>
	</div>
</template>

<script>
import LotteryApi from "@/api/lottery.js";
import Send from "./dialog/Send.vue";
import remarks from "./dialog/remarks.vue";
import qs from "qs";
import { useUserStore } from "@/store";
const {
  token
} = useUserStore();
import Logistics from "@/components/logistics/viewLogistics.vue";
export default {
  components: {
    Send,
    Logistics,
    remarks
  },
  data() {
    return {
      token,
      /*是否加载完成*/
      loading: true,
      /*列表数据*/
      tableData: [],
      /*一页多少条*/
      pageSize: 20,
      /*一共多少条数据*/
      totalDataNumber: 0,
      /*当前是第几页*/
      curPage: 1,
      /*横向表单数据模型*/
      formInline: {
        search: "",
        reg_date: "",
        status: "",
        recordName: ""
      },
      open_send: false,
      currentModel: {},
      expressList: [],
      logisticsData: {},
      isLogistics: false,
      is_remark: false,
      remarkVal: {}
    };
  },
  created() {
    /*获取列表*/
    this.getTableList();
  },
  methods: {
    remarks(e) {
      this.remarkVal = e;
      this.is_remark = true;
    },
    openLogistics() {
      this.isLogistics = true;
      console.log(this.isLogistics);
    },
    closeLogistics() {
      this.isLogistics = false;
    },
    getLogistics(row) {
      let self = this;
      let Params = {
        recordId: row.recordId,
        expressId: row.expressId,
        expressNo: row.expressNo
      };
      self.loading = true;
      LotteryApi.express(Params, true).then(res => {
        self.loading = false;
        self.logisticsData = res.data.express.data;
        self.openLogistics();
      }).catch(error => {
        self.loading = false;
      });
    },
    onExport: function () {
      let self = this;
      let Params = {
        search: self.formInline.search,
        recordName: self.formInline.recordName,
        status: self.formInline.status,
        pageIndex: self.curPage,
        pageSize: self.pageSize
      };
      Params.tokenshop = self.token;
      let baseUrl = import.meta.env.VITE_BASIC_URL;
      if (!baseUrl) {
        baseUrl = window.location.protocol + "//" + window.location.host;
      }
      window.location.href = baseUrl + "/api/shop/plus/lottery/recordExport?" + qs.stringify(Params);
    },
    /*选择第几页*/
    handleCurrentChange(val) {
      let self = this;
      self.curPage = val;
      self.loading = true;
      self.getTableList();
    },
    /*每页多少条*/
    handleSizeChange(val) {
      this.curPage = 1;
      this.pageSize = val;
      this.getTableList();
    },
    /*获取列表*/
    getTableList() {
      let self = this;
      let Params = self.formInline;
      Params.pageIndex = self.curPage;
      Params.pageSize = self.pageSize;
      if (self.formInline.reg_date != "") {
        Params.startTime = Params.reg_date[0];
        Params.endTime = Params.reg_date[1];
      }
      LotteryApi.recordList(Params, true).then(res => {
        self.loading = false;
        self.tableData = res.data.list.records;
        self.totalDataNumber = res.data.list.total;
        self.expressList = res.data.expressList;
      }).catch(error => {
        self.loading = false;
      });
    },
    /*搜索查询*/
    onSubmit() {
      let self = this;
      self.loading = true;
      self.curPage = 1;
      self.getTableList();
    },
    sendClick(e) {
      this.open_send = true;
      this.currentModel = e;
    },
    /*关闭弹窗*/
    closeDialogFunc(e, f) {
      if (f == "Send") {
        this.open_send = e.openDialog;
        if (e.type == "success") {
          this.getTableList();
        }
      } else if (f == "remark") {
        this.is_remark = e.openDialog;
        if (e.type == "success") {
          this.getTableList();
        }
      }
    }
  }
};
</script>

